﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Nature.Toolkit.GMix.Generic
{
    public static class Rhs
    {
        public static RhsQuestion Question { get { return new RhsQuestion(); } }

        public static RhsValue Value(double value) { return new RhsValue(value); }

        public static RhsEnumerable Enumerable(string parameterName, IEnumerable<double> data) { return new RhsEnumerable(parameterName, data); }

        public static IRhs Value(double? rhs)
        {
            return rhs.HasValue ? (IRhs)new RhsValue(rhs.Value) : (IRhs)new RhsQuestion();
        }
    }

    [DebuggerDisplay("?")]
    [Serializable]
    public class RhsQuestion : IRhsQuestion { }


    [DebuggerDisplay("{Value}")]
    [Serializable]
    public class RhsValue : IRhsValue
    {
        public RhsValue(double value)
        {
            this.Value = value;
        }

        public static implicit operator RhsValue(double value) { return new RhsValue(value); }

        #region IRhsValue Members

        public double Value
        {
            get;
            private set;
        }

        #endregion
    }

    [DebuggerDisplay("Enumerable")]
    [Serializable]
    public class RhsEnumerable : IRhsEnumerable
    {
        #region Private Fields
        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
        private IEnumerable<double> m_data; 
        #endregion

        public RhsEnumerable(string parameterName, IEnumerable<double> data)
        {
            this.ParameterName = parameterName;
            m_data = data;
            if (parameterName == null) { throw new ArgumentNullException("parameterName"); }
            if (data == null) { throw new ArgumentNullException("data"); }
        }

        #region IRhsEnumerable Members

        public string ParameterName
        {
            get;
            private set;
        }

        #endregion

        #region IEnumerable<double> Members

        public IEnumerator<double> GetEnumerator()
        {
            return m_data.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return m_data.GetEnumerator();
        }

        #endregion
    }


}
